package com.i2863.tools.weixinmp.service;


import com.i2863.tools.weixinmp.dao.mapper.WeixinMapper;
import com.i2863.tools.weixinmp.domain.Weixin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by xuweiwei on 2017/3/10.
 */
@Service("weixinService")
public class WeixinService {

    private static final Logger logger = LoggerFactory.getLogger(WeixinService.class);

    @Resource
    private WeixinMapper mapper;


    public List<Weixin> getAllWeixin() {
        return mapper.getAllWeixin();
    }

    public List<Weixin> getWeixinByArea(Integer siteId, String province, String city) {
        return mapper.getWeixinByArea(siteId, province, city);
    }

    public void save(String name, String code, Integer siteId, String province, String city) {
        Weixin w = mapper.getWeixinByCode(code);
        if (w == null) {
            w = new Weixin();
            w.setCode(code);
            w.setName(name);
            w.setSiteId(siteId);
            w.setProvince(province);
            w.setCity(city);
            mapper.save(w);
        }
    }

    public void delete(String code) {
        mapper.delete(code);
    }

    public Weixin getWeixinByCode(String code) {
        return mapper.getWeixinByCode(code);
    }


}
